package com.family.web.controller.pedigree;


import com.family.common.annotation.Log;
import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.common.enums.BusinessType;
import com.family.pedigree.domain.FamilyProcessInstance;
import com.family.pedigree.service.IFamilyProcessInstanceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 流程实例 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/family/process/instance")
public class FamilyProcessInstanceController extends BaseController {

    private final IFamilyProcessInstanceService interfaceService;

    @RequestMapping("/list")
    public TableDataInfo list(FamilyProcessInstance instance) {
        startPage();
        return getDataTable(interfaceService.getList(instance));
    }


    @Log(title = "添加流程实例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyProcessInstance instance) {
        return toAjax(interfaceService.save(instance));
    }

    @Log(title = "修改流程实例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyProcessInstance instance) {
        return toAjax(interfaceService.updateById(instance));
    }

    @Log(title = "发送流程实例", businessType = BusinessType.UPDATE)
    @PutMapping("/sendOrCancel")
    public AjaxResult sendAnd(@RequestBody FamilyProcessInstance instance) {
        return toAjax(interfaceService.send(instance));
    }


    @Log(title = "删除流程实例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{instanceId}")
    public AjaxResult delById(@PathVariable Long instanceId) {
        return toAjax(interfaceService.removeById(instanceId));
    }

    /**
     * 已办代办列表
     */
    @GetMapping("/wait/list")
    public TableDataInfo wait(FamilyProcessInstance instance) {
        startPage();
        return getDataTable(interfaceService.getWaitList(instance));
    }

    @GetMapping("/done/list")
    public TableDataInfo manageList(FamilyProcessInstance instance) {
        startPage();
        return getDataTable(interfaceService.getDoneList(instance));
    }

    /**
     * 处理流程
     */
    @Log(title = "处理流程", businessType = BusinessType.UPDATE)
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody FamilyProcessInstance instance) {
        return toAjax(interfaceService.handle(instance));
    }


}
